﻿@model ConferenceScheduleReportModel
@{
	ViewBag.Title = Resources.ConferenceScheduleReport + ConstValues.strDash + ViewBag.ConferenceName;
}
<div id="menuBar" style="height:35px;">
	<div style="float: left; padding: 5px 5px; font-weight: bold; text-align: left;">
		@Resources.ReportType：<select id="selReport" class="easyui-combobox" style="height:27px; width:200px;"></select>&nbsp;&nbsp;
		@Resources.SchedulePlace：<input id="selSchedulePlace" class="easyui-textbox" style="height:27px; width:200px;" />&nbsp;&nbsp;
		@Resources.TopicName：<select id="selTopic" class="easyui-combobox" style="height:27px; width:200px;"></select>&nbsp;&nbsp;
		@Resources.Name/@Resources.Affiliation：<input id="selNameAffiliation" class="easyui-textbox" style="height:27px; width:200px;" />&nbsp;&nbsp;
		<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" onclick="searchData();">@Resources.Search</a>&nbsp;&nbsp;
		<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-export" onclick="exportData();" plain="true">@Resources.ExportPresentationLog</a>
	</div>
	<form id="frmExport" method="post" target="iframeDownload" action="@Url.Action(nameof(ConferenceScheduleReportController.Export))">
		@Html.AntiForgeryToken()
		<input type="hidden" id="hdnIds" name="AllId" />
		<input type="hidden" id="hidExtConferenceId" name="ConferenceId" />
	</form>
	<iframe id="iframeDownload" style="width:0; height:0; visibility:hidden" tabindex="-1"></iframe>
	<form id="setAllConfirmForm" method="post">
		@Html.AntiForgeryToken()
		<input type="hidden" id="hdnAllConfirmIds" name="hdnAllConfirmIds" />
		<input type="hidden" id="conferenceIdForConfirm" name="ConferenceId" />
		<input type="hidden" id="allConfirmFlag" name="allConfirmFlag" />
	</form>
	<div class="clear"></div>
</div>
<div id="dataGrid"></div>

@section bodyParts {
<div id="detailWindow" class="easyui-window"
	title="@Resources.Remark" data-options="closed:true,minimizable:false,iconCls:'icon-save'"
	style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="detailWindowTitle" class="tit01">@Resources.Remark</h3>
			<form id="frmDetail" method="post">
				@Html.AntiForgeryToken()
				<table width="100%" height="100%" id="tblDetail" cellpadding="0" cellspacing="1" border="0" class="tastyle01">
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.Remark：</td>
						<td style="text-align: left;" class="w2 c2" colspan="3">
							<input type="hidden" id="hidID" name="Id" />
							<input type="hidden" id="hidConferenceId" name="ConferenceId" />
							<input id="txtRemark" name="Remark" class="easyui-textbox" style="height:100px; width:892px;" data-options="multiline:true, validType:['length[1,1000]']" />
						</td>
					</tr>
				</table>
			</form>
			<div class="btnDiv">
				<input type="button" class="gbtn" onclick="saveData();" value="@Resources.Save" />&nbsp;&nbsp;
				<input type="button" class="rbtn" onclick="$('#detailWindow').window('close');" value="@Resources.Cancel" />
			</div>
		</div>
	</div>
</div>
<div id="authorWindow" class="easyui-window"
	title="@Resources.Author" data-options="closed:true,minimizable:false,maximizable:false,iconCls:'icon-save'"
	style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="detailWindowTitle" class="tit01">@Resources.Check</h3>
			<div id="authorDG"></div>
		</div>
	</div>
</div>
<div id="logWindow" class="easyui-window"
	title="@Resources.ConferenceScheduleReport" data-options="closed:true,minimizable:false,iconCls:'icon-save'"
	style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="logWindowTitle" class="tit01">@Resources.PresentationLog</h3>
			<form id="logDetail" method="post" enctype="multipart/form-data">
				@Html.AntiForgeryToken()
				<table width="100%" height="100%" id="tblDetail" cellpadding="0" cellspacing="1" border="0" class="tastyle01">
					<tr>
						<td style="text-align: right;" class="w1 c1">@Resources.Attendance：</td>
						<td style="text-align: left;" class="w2 c2">
							<input type="hidden" id="logId" name="logId">
							<input id="selAttendance" name="attendance" class="easyui-combobox" style="height:27px; width:300px;" />
						</td>
						<td style="text-align: right;" class="w1 c1">@Resources.AttendanceDescription：</td>
						<td style="text-align: left;" class="w2 c2">
							<input id="txtAttendanceDescription" name="description" class="easyui-textbox" style="height:27px; width:300px;" data-options="validType:['length[1,100]']">
						</td>
					</tr>								
					<tr>
						<td style="text-align: right;" class="w1 c3">@Resources.PresentationLog：</td>
						<td style="text-align: left;" class="w2 c4" colspan="3">
							<input id="txtPresentationLog" name="summary" class="easyui-textbox" style="height:50px; width:892px;" data-options="multiline:true,validType:['length[1,1000]']" />
						</td>
					</tr>
				</table>
			</form>
			<div class="btnDiv">
				<input type="hidden" id="hdnWindowType" />
				<input type="button" class="gbtn" onclick="saveLogData();" value="@Resources.Save" />&nbsp;&nbsp;
				<input type="button" class="rbtn" onclick="$('#logWindow').window('close');" value="@Resources.Cancel" />
			</div>
		</div>
	</div>
</div>
}

@section Scripts {
<script>
	common.setCurrentMenu("ConferenceScheduleReport");
	common.setCurrentParentMenu("#menu_a8");

	$(function () {
		$("#hidConferenceId").val("@Model.ConferenceId");
		$("#hidExtConferenceId").val("@Model.ConferenceId");
		$("#conferenceIdForConfirm").val("@Model.ConferenceId");

		var selTopic = 0;
		$("#selTopic").combobox({
			editable: false,
			valueField: "id",
			textField: "name",
			url: "@Url.Action(nameof(UtilityController.GetTopicWithAll),
			nameof(UtilityController).GetControllerName())"
					+ "?conferenceId=" + $("#hidConferenceId").val(),
			onLoadSuccess: function(data) {
				selTopic = data.length;
			},
			onShowPanel: function () {
				if (selTopic < 10) {
					$(this).combobox("panel").height("auto");
				} else {
					$(this).combobox("panel").height(200);
				}
			},
		});

		var selReport = 0;
		$("#selReport").combobox({
			editable: false,
			valueField: "id",
			textField: "name",
			url: "@Url.Action(nameof(UtilityController.GetReportWithAll),
			nameof(UtilityController).GetControllerName())"
					+ "?conferenceId=" + $("#hidConferenceId").val(),
			onLoadSuccess: function(data) {
				selReport = data.length;
			},
			onShowPanel: function () {
				if (selReport < 10) {
					$(this).combobox("panel").height("auto");
				} else {
					$(this).combobox("panel").height(200);
				}
			},
		});

		$("#selReport").textbox("textbox").bind("keydown", function (e) {
			if (e.keyCode == 13) {
				searchData()
			}
		});
		$("#selSchedulePlace").textbox("textbox").bind("keydown", function (e) {
			if (e.keyCode == 13) {
				searchData()
			}
		});
		$("#selTopic").textbox("textbox").bind("keydown", function (e) {
			if (e.keyCode == 13) {
				searchData()
			}
		});
		$("#selNameAffiliation").textbox("textbox").bind("keydown", function (e) {
			if (e.keyCode == 13) {
				searchData()
			}
		});

		$("#selAttendance").combobox({

			editable: false,
			valueField: "id",
			textField: "name",
			url: "@Url.Action(nameof(UtilityController.GetAttendenceInfoType), nameof(UtilityController).GetControllerName())"+ "?conferenceId=" + $("#hidConferenceId").val(),
			onShowPanel: function () {
				$(this).combobox("panel").height("auto");
			},
		});

		$("#dataGrid").datagrid({
			url: "@Url.Action(nameof(ConferenceScheduleReportController.GetData),
			nameof(ConferenceScheduleReportController).GetControllerName(),
			new { ConferenceId = Model.ConferenceId })",
			method: "get",
			checkOnSelect: false,
			//singleSelect: true,
			fitColumns: true,
			width: $(window).width() - 285,
			height: $(window).height() - 158,
			nowrap: false,
			pagination: true,
			remoteSort:true,
			pageSize: @ConstValues.DefaultGridRows,
			striped: true,
			toolbar: "#toolBar",
			pageSize: 100,
			pageList: [100, 200, 300, 400, 500],
			columns: [[
				{ field: "chk", align: "center", checkbox: true },
				@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) ||
					Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceScheduleReport, RoleType.修改))
				{
					<text>
					{
						field: "operate", title: "@Resources.Operate", align: "center", width: 150,
						formatter: function(value, rec) {
							var strInfo = "";
							@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceScheduleReport, RoleType.修改))
							{
								<text>
								strInfo += "<a href='#' style='color:#66CDAA;font-weight:bold;text-decoration:underline;' onclick='editData(\""
									+ rec.id + "\")'>@Resources.Remark</a>";
								strInfo += " | <a href='#' style='color:#FF8C00;font-weight:bold;text-decoration:underline;' onclick='logData(\""
									+ rec.id + "\")'>@Resources.PresentationLog</a> ";
								</text>
							}
							return strInfo;
						}
					},
					</text>
				}
				{ field: "scheduleTime", title: "@Resources.ScheduleTime", align: "center", width: 150 },
				{ field: "schedulePlace", title: "@Resources.SchedulePlace", align: "center", sortable: true, width: 150 },
				{ field: "reportType", title: "@Resources.ReportType", align: "center", sortable: true, width: 100 },
				{ field: "topicName", title: "@Resources.TopicName", align: "center", sortable: true, width: 170 },
				{ field: "id", title: "@Resources.ContributionID", align: "center", sortable: true, width: 170 },
				{ field: "essayTitle", title: "@Resources.EssayTitle", align: "center", sortable: true, width: 170 },
				{ field: "fullName", title: "@Resources.Presenter", align: "center", sortable: true, width: 100 },
				{ field: "affiliation", title: "@Resources.Affiliation", align: "center", sortable: true, width: 100 },
				{
					field: "author", title: "@Resources.Author", align: "center", width: 100,
					formatter: function(value, rec) {
						var strInfo = "<a href='#' style='color:#FF8C00;font-weight:bold;text-decoration:underline;' onclick='openAuthor(\""
							+ rec.id + "\")'>@Resources.Check</a>";
						return strInfo;
					}
				},
				{
					field: "isConfirm", title: "<input type='checkbox' id='setAllConfirm' onclick='setAllConfirm()' style='display:inline-block;float:left;margin-top:6px;'><a style='float:left;display:inline-block;margin-top:4px;'>@Resources.IsConfirm</a>", align: "center", width: 120,
					formatter: function(value, rec) {
						var strInfo = "";
						if (rec.scheduleStatus == "@Resources.ScheduleStatusWait")
						{
							strInfo = "<input type='checkbox' style='margin-top:8px;' onchange='changeConfirm(\"" + rec.id + "\")' checked/>";
						} else if (rec.scheduleStatus == "@Resources.ScheduleStatusNo")
						{
							strInfo = "<input type='checkbox' style='margin-top:8px;' onchange='changeConfirm(\"" + rec.id + "\")' />";
						} else {
							if (value == true) {
								strInfo = "<input type='checkbox' style='margin-top:8px;' disabled='false' checked/>";
							} else {
								strInfo = "<input type='checkbox' style='margin-top:8px;' onchange='changeConfirm(\"" + rec.id + "\")' />";
							}
						}
						return strInfo;
					}
				},
				{ field: "scheduleStatus", title: "@Resources.ScheduleStatus", align: "center", sortable: true, width: 100 },
				{ field: "remark", title: "@Resources.Remark", align: "center", sortable: true, width: 100 },
				{
					field: "attendance", title: "@Resources.Attendance", align: "center", sortable: true, width: 100,
					formatter: function(value, rec) {
						if (value=="@ConstValues.AttendenceInfoType.本人出席") {
							return "@Resources.AttendenceInfoTypeSelf"
						} else if (value=="@ConstValues.AttendenceInfoType.他人代讲") {
							return "@Resources.AttendenceInfoTypeOther"
						} else if (value=="@ConstValues.AttendenceInfoType.未出席") {
							return "@Resources.AttendenceInfoTypeAbsent"
						} else if (value=="@ConstValues.AttendenceInfoType.其他") {
							return "@Resources.AttendenceInfoTypeOthers"
						} else {
							return ""
						}
					}
				},
				{ field: "description", title: "@Resources.AttendanceDescription", align: "center", sortable: true, width: 100 },
			]],
			onBeforeLoad: function(param) {
				param.conferenceId = $("#hidConferenceId").val();
				param.random = Math.random();
			},
			onLoadSuccess: function(data) {
				var exportIdList = $("#hdnIds").val();
				if (data.rows.length > 0 && exportIdList != "") {
					var exportIdArray = exportIdList.split(',');
					for (var rowIndex = 0; rowIndex < data.rows.length; rowIndex++) {
						for (var index = 0; index < exportIdArray.length; index++) {
							if (data.rows[rowIndex].presenterId == exportIdArray[index]) {
								$("input[type='checkbox']").eq(rowIndex + 1).prop("checked", true);
								break;
							}
						}
					}
				}
			},
			onCheck: function (rowIndex, rowData) {
				var exportIdList = $("#hdnIds").val();
				var strId = rowData.presenterId.toString();
				if (exportIdList == "") {
					$("#hdnIds").val(strId);
				} else {
					var exportIdArray = exportIdList.split(',');
					var newArray = exportIdArray.concat(strId);
					$("#hdnIds").val(newArray.join());
				}
			},
			onUncheck: function (rowIndex, rowData) {
				var exportIdList = $("#hdnIds").val();
				var exportIdArray = exportIdList.split(',');
				var strId = rowData.presenterId.toString();
				exportIdArray.remove(strId);
				$("#hdnIds").val(exportIdArray.join());
			},
			onCheckAll: function (rows) {
				var exportIdList = $("#hdnIds").val();
				if (exportIdList == "") {
					var newArray = new Array();
					for (var index = 0; index < rows.length; index++) {
						var strId = rows[index].presenterId.toString();
						newArray = newArray.concat(strId);
					}
					$("#hdnIds").val(newArray.join());
				} else {
					var exportIdArray = exportIdList.split(',');
					var newArray = exportIdArray;
					for (var index = 0; index < rows.length; index++) {
						var strId = rows[index].presenterId.toString();
						if (newArray.indexOf(strId) < 0) {
							newArray = newArray.concat(strId);
						}
					}
					$("#hdnIds").val(newArray.join());
				}
			},
			onUncheckAll: function (rows) {
				var exportIdList = $("#hdnIds").val();
				var exportIdArray = exportIdList.split(',');
				for (var index = 0; index < rows.length; index++) {
					var strId = rows[index].presenterId.toString();
					exportIdArray.remove(strId);
				}
				$("#hdnIds").val(exportIdArray.join());
			},
		});

		$(window).resize(function () {
			$("#dataGrid").datagrid("resize", {
				width: $(window).width() - 285,
				height: $(window).height() - 158
			});

		});

		$("#detailWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			top: ($(window).height() - 600) * 0.5
		});

		$("#authorWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			top: ($(window).height() - 600) * 0.5
		});

		$("#logWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			top: ($(window).height() - 600) * 0.5
		});
	});

	function searchData() {
		$("#dataGrid").datagrid("load", {
			SelReport: $("#selReport").combobox("getValue"),
			SelSchedulePlace: $("#selSchedulePlace").textbox("getValue"),
			SelTopic: $("#selTopic").combobox("getValue"),
			SelNameAffiliation: $("#selNameAffiliation").textbox("getValue")
		});
	}

	function openAuthor(id) {
		$("#authorDG").datagrid({
			url: "@Url.Action(nameof(UtilityController.GetAuthorList),
					nameof(UtilityController).GetControllerName())",
			method: "get",
			checkOnSelect: false,
			selectOnCheck: false,
			height: 532,
			nowrap: false,
			pageSize: @ConstValues.DefaultGridRows,
			striped: true,
			singleSelect: true,
			singleCheck: true,
			frozenColumns: [[
				{ field: "sort", title: "@Resources.Sort", align: "center", width: 50 },
				{ field: "fullName", title: "@Resources.FullName", align: "center", width: 200 },
				{ field: "mail", title: "@Resources.Mail", align: "center", width: 250 },
			]],
			columns: [[
				{ field: "affiliation", title: "@Resources.Affiliation", align: "center", width: 200 },
				{ field: "department", title: "@Resources.Department", align: "center", width: 100 },
				{
					field: "status", title: "@Resources.Status", align: "center",  width: 100,
					formatter: function(value, rec) {
						if (value=="@ConstValues.Status.正常") {
							return "@Resources.Normal"
						} else {
							return "@Resources.Pause"
						}
					}
				},
				{
					field: "isPresenter", title: "@Resources.Presenter", align: "center", width: 150,
					formatter: function(value, rec) {
						if (value == true) {
							return "@Resources.Yes"
						} else {
							return "@Resources.No"
						}
					}
				},
				{ field: "familyName", title: "@Resources.FamilyName", align: "center", width: 100 },
				{ field: "firstName", title: "@Resources.FirstName", align: "center", width: 100 },
				{ field: "country", title: "@Resources.Country", align: "center", width: 100 },
				{ field: "state", title: "@Resources.State", align: "center", width: 100 },
				{ field: "city", title: "@Resources.City", align: "center", width: 100 },
				{ field: "address", title: "@Resources.Address", align: "center", width: 300 },
				{ field: "zipCode", title: "@Resources.ZipCode", align: "center", width: 100 },
				{ field: "mobile", title: "@Resources.Mobile", align: "center", width: 100 },
				{ field: "ccMail", title: "@Resources.CcMail", align: "center", width: 100 },
				{ field: "selfIntroduction", title: "@Resources.SelfIntroduction", align: "center", width: 100 },
				{ field: "remark", title: "@Resources.Remark", align: "center", width: 200 },
			]],
			onBeforeLoad: function(param) {
				param.id = id;
				param.random = Math.random();
			}
		});

		$("#authorWindow").window("open");
	}

	function editData(id) {
		var url = "@Url.Action(nameof(ConferenceScheduleReportController.GetEditData),
				nameof(ConferenceScheduleReportController).GetControllerName())" + "/" + id;
		$.get(url, null, function (data, textStatus, jqXHR) {
			if (data.result == "@ConstValues.AjaxFailResult") {
				common.showError(data.message);
				$("#dataGrid").datagrid("reload");
			} else {
				$("#hidID").val(id);
				$("#txtRemark").textbox("setValue", data.data.remark);
				$("#detailWindow").window("open");
			}
		});
	}

	function saveData() {
		$.messager.confirm("@Resources.Save", "@Resources.CfmSave", function (r) {
			if (r) {
				var loading = layer.load(0,  {
					shade: [0.4,"#fff"]
				});

				$.post("@Url.Action(nameof(ConferenceScheduleReportController.Modify),
						nameof(ConferenceScheduleReportController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
					$("#frmDetail").serialize(),
					function(data, textStatus, jqXHR) {
						layer.close(loading);
						if (data.result == "@ConstValues.AjaxFailResult") {
							common.showError(data.message);
						} else {
							common.showSuccess(data.message, true);
							$("#detailWindow").window("close");
							$("#dataGrid").datagrid("reload");
						}
					}
				);
			}
		});
	}

	function changeConfirm(id) {
		$("#hidID").val(id);
		var loading = layer.load(0,  {
			shade: [0.4,"#fff"]
		});

		$.post("@Url.Action(nameof(ConferenceScheduleReportController.ChangeConfirm),
				nameof(ConferenceScheduleReportController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
			$("#frmDetail").serialize(),
			function(data, textStatus, jqXHR) {
				layer.close(loading);
				if (data.result == "@ConstValues.AjaxFailResult") {
					common.showError(data.message);
				} else {
					common.showSuccess(data.message, true);
					$("#detailWindow").window("close");
					$("#dataGrid").datagrid("reload");
				}
			}
		);
	}

	function exportData(){
		var exportIdList = $("#hdnIds").val();
		if (exportIdList == "") {
			$.messager.alert("@Resources.Export", "@Resources.MsgRecordMust", "warning");
			return;
		}
		$("#frmExport").submit();
	}

	function setAllConfirm() {
		if ($("#setAllConfirm").is(":checked")) {
			$("#allConfirmFlag").val("true");
		} else {
			$("#allConfirmFlag").val("false");
		}
		var rows = $("#dataGrid").datagrid("getRows");
		var newArray = new Array();
		for (var index = 0; index < rows.length; index++) {
			var strId = rows[index].id.toString();
			newArray = newArray.concat(strId);
		}
		$("#hdnAllConfirmIds").val(newArray.join());

		var url = "@Url.Action(nameof(ConferenceScheduleReportController.SetAllConfirm),
				nameof(ConferenceScheduleReportController).GetControllerName())"
		$.post(url, $("#setAllConfirmForm").serialize(), function (data, textStatus, jqXHR) {
			if (data.result == "@ConstValues.AjaxFailResult") {
				common.showError(data.message);
			} else {
				$("#dataGrid").datagrid("reload");
			}
		});
	}

	function logData(id) {
		$("#logId").val(id);

		var url = "@Url.Action(nameof(ConferenceScheduleReportController.GetLogData),
				nameof(ConferenceScheduleReportController).GetControllerName())" + "/" + id;
		$.get(url, null, function (data, textStatus, jqXHR) {
			if (data.result == "@ConstValues.AjaxFailResult") {
				common.showError(data.message);
			} else {
				$("#selAttendance").combobox("setValue", data.data.attendance);
				$("#txtAttendanceDescription").textbox("setValue", data.data.description);
				$("#txtPresentationLog").textbox("setValue", data.data.summary);
				$("#logWindow").window("open");
			}
		});
	}

	function saveLogData() {
		$.messager.confirm("@Resources.Save", "@Resources.CfmSave", function (r) {
			if (r) {
				var loading = layer.load(0,  {
					shade: [0.4,"#fff"]
				});

				$.post("@Url.Action(nameof(ConferenceScheduleReportController.SaveLogData),
						nameof(ConferenceScheduleReportController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
					$("#logDetail").serialize(),
					function(data, textStatus, jqXHR) {
						layer.close(loading);
						if (data.result == "@ConstValues.AjaxFailResult") {
							common.showError(data.message);
						} else {
							common.showSuccess(data.message, true);
							$("#logWindow").window("close");
							$("#dataGrid").datagrid("reload");
						}
					}
				);
			}
		});
	}
</script>
}